import { Component, Input, OnInit, TemplateRef } from '@angular/core'

import { IBaseInfoColumn } from '@shared/interfaces/baseInfo'

@Component({
  selector: 'app-detail-channel',
  templateUrl: './detail-channel.component.html',
})
export class DetailChannelComponent implements OnInit {

  /* 首行的项 */
  firstColumns: IBaseInfoColumn[] = []

  /* 首行宽度 */
  firstSpans = 24

  /* 其他项 */
  restColumns: IBaseInfoColumn[][] = []

  @Input() imgUrl: string

  @Input() channelName: string | TemplateRef<void>

  @Input() columns: Array<IBaseInfoColumn[]>

  @Input() rowIndex: number

  @Input() operationZone: TemplateRef<void>

  constructor() {}

  ngOnInit() {
    for (const o of this.columns) {
      for (const i of o) {
        if (i.operate) {
          i.template = this.operationZone
        }
      }
    }
    this.parseColumns()
  }

  parseColumns(): void {
    this.firstColumns = this.columns.shift()
    this.restColumns = this.columns
  }

}
